package volatiledemo;

/**
 * @description:
 * @author: jhy
 * @time: 2021/4/12 15:36
 */

//volatile关键字不能保证原子性
public class VolatileDemo2 {

    public static void main(String[] args) {
        MyThread[] myThreads = new MyThread[100];
        for(int i = 0;i < 100;i++){
            myThreads[i] = new MyThread();
        }

        for(int i = 0;i < 100;i++){
            myThreads[i].start();
        }
    }
}

class MyThread extends Thread{

    public volatile static int count;

    @Override
    public void run() {
        for(int i = 0;i < 100;i++){
            count++;
        }
        System.out.println("count = " + count);
    }
}
